package com.hdoit.ares.selfcommon.utils;

import java.math.BigDecimal;

import com.singularsys.jep.Jep;
import com.tennetcn.common.message.SearchModel;

public class ExpressionUtil extends SearchModel{

	public static double stringToDouble(String str,double percent){
		Jep jep = new Jep();
		Object result = 0;
		try {
			if(str.indexOf("x") != -1){
				String real = str.replaceAll("x", String.valueOf(percent));
				System.err.println("是否替换：\t" + real );
				jep.parse(real);
			}else{
				jep.parse(str);
			}
			
			result = jep.evaluate();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		System.err.println("验证计算公式是否正确" + result);
		
		return new BigDecimal(String.valueOf(result)).setScale(3, BigDecimal.ROUND_DOWN).doubleValue();
	}
}
